MODULE = hertz-admin
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)

IMAGE_NAME := tcs-sup-backend
IMAGE_TAG := $(shell echo $(BRANCH) | sed 's/\(v[0-9\x2e]*\).*/\1/')
REPOSITORY := 192.168.8.148:20443/tcs/tcs-sup-backend
TARGET_DIR := /opt/build-host/tcs/$(IMAGE_TAG)

# 运行
.PHONY: run
run:
	go run main.go server

.PHONY: build
build:
	go build -o tcs-sup-backend main.go

# 打包成docker镜像
.PHONY: docker
TAG := $(IMAGE_NAME):$(IMAGE_TAG)
docker:
	@echo "Building image with tag '$(TAG)'"
	docker build -f ./build/docker/Dockerfile -t $(TAG) .
	docker save -o $(TARGET_DIR)/$(IMAGE_NAME)-$(IMAGE_TAG).tar $(TAG)
	gzip $(TARGET_DIR)/$(IMAGE_NAME)-$(IMAGE_TAG).tar
	docker image prune -f

.PHONY: push_docker
push_docker:
	@echo "Pushing image with tag '$(IMAGE_TAG)' to repository '$(REPOSITORY)'"
	docker tag $(IMAGE_NAME):$(IMAGE_TAG) $(REPOSITORY):$(IMAGE_TAG)
	docker login -u admin -p 123456 192.168.8.148:20443
	docker push $(REPOSITORY):$(IMAGE_TAG)



.PHONY: test
test:
	@go test -v -failfast  -count=1 -timeout 10s